k = int(input())
d = 0
if len(str(k)) == 4:
    for i in range(2, k // 2 + 1):
        if k % i == 0:
            break
    else:
    d = k
    g = str(k)
    for i in range(len(g)):
        for j in range(i+1, len(g)+1):
            if i == 0 and g[i] == '0':
                continue
            w = int(g[i:j])
            for k in range(2, w):
                if w % k == 0:
                    break
            else:
                if w > d:
                    d = w

print(d)
